package com.uphone.edwards.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;


import com.uphone.edwards.R;
import com.uphone.edwards.util.SharedUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 我的文档 on 2017-12-16.
 */
public class LanguageAdapter extends MybaseAdapter<Integer> {
    private Context mContext;
    public LanguageAdapter(Context context) {
        super(context);
        this.mContext = context;
    }

    @Override
    public View setView(final int posi, View converView, ViewGroup parent) {
        final ViewHolder holderView;
        if (converView == null) {
            converView = inflater.inflate(R.layout.item_lang, null);
            holderView = new ViewHolder(converView);
            converView.setTag(holderView);
        } else {
            holderView = (ViewHolder) converView.getTag();
        }
        int item = getItem(posi);
        if (posi == 0){
            holderView.tvLang.setText("中文");
            holderView.tvLangS.setText("中文");
        }
        if (posi == 1){
            holderView.tvLang.setText("English");
            holderView.tvLangS.setText("English");
        }
        if (posi == 3){
            holderView.tvLang.setText("한글");
            holderView.tvLangS.setText("한글");
        }
        if (posi == 2){
            holderView.tvLang.setText("日本語");
            holderView.tvLangS.setText("日本語");
        }
        holderView.tvLangSelect.setText("(" + mContext.getResources().getString(item) + ")");
        if ("ch".equals(SharedUtils.getShareLanguage(mContext))){
            if (posi == 0){
                holderView.llLangN.setVisibility(View.GONE);
                holderView.tvLangS.setVisibility(View.VISIBLE);
            }else{
                holderView.llLangN.setVisibility(View.VISIBLE);
                holderView.tvLangS.setVisibility(View.GONE);
            }
        }
        if ("en".equals(SharedUtils.getShareLanguage(mContext))){
            if (posi == 1){
                holderView.llLangN.setVisibility(View.GONE);
                holderView.tvLangS.setVisibility(View.VISIBLE);
            }else{
                holderView.llLangN.setVisibility(View.VISIBLE);
                holderView.tvLangS.setVisibility(View.GONE);
            }
        }
        if ("ja".equals(SharedUtils.getShareLanguage(mContext))){
            if (posi == 2){
                holderView.llLangN.setVisibility(View.GONE);
                holderView.tvLangS.setVisibility(View.VISIBLE);
            }else{
                holderView.llLangN.setVisibility(View.VISIBLE);
                holderView.tvLangS.setVisibility(View.GONE);
            }
        }
        if ("ko".equals(SharedUtils.getShareLanguage(mContext))){
            if (posi == 3){
                holderView.llLangN.setVisibility(View.GONE);
                holderView.tvLangS.setVisibility(View.VISIBLE);
            }else{
                holderView.llLangN.setVisibility(View.VISIBLE);
                holderView.tvLangS.setVisibility(View.GONE);
            }
        }

        return converView;
    }
    class ViewHolder{
        public TextView tvLang;
        public TextView tvLangSelect;
        public TextView tvLangS;
        private LinearLayout llLangN;

        public ViewHolder(View v){
            tvLang = v.findViewById(R.id.tv_lang);
            tvLangSelect = v.findViewById(R.id.tv_lang_select);
            tvLangS = v.findViewById(R.id.tv_lang_s);
            llLangN = v.findViewById(R.id.ll_lang_n);
        }
    }
}
